// 格式化 create_at 为 yyyy-mm-dd hh:mm:ss
const formattedArticles = (articles, key) => {
  return articles.map(article => {
    const date = new Date(article?.[key]);
    const formattedDate = [
      date.getFullYear(),
      String(date.getMonth() + 1).padStart(2, '0'),
      String(date.getDate()).padStart(2, '0')
    ].join('-') + ' ' + [
      String(date.getHours()).padStart(2, '0'),
      String(date.getMinutes()).padStart(2, '0'),
      String(date.getSeconds()).padStart(2, '0')
    ].join(':');
    return { ...article, [key]: formattedDate };
  });
} 

module.exports = {
  formattedArticles
}